package com.itrencai.d8_stream;

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

//目标：收集stream流的数据到集合或数组中去
public class StreamDemo2shouji {
    public static void main(String[] args) {
        List<String> names=new ArrayList<>();
        Collections.addAll(names,"张三丰","张无忌","赵敏","周芷若","张强","张三丰");
        Stream<String> s1 = names.stream().filter(s-> s.startsWith("张"));
        //List<String> list1=s1.toString();//得到不可变集合
        List<String> zhangList= s1.collect(Collectors.toList());//可变集合
        System.out.println(zhangList);

        //"流只能使用一次"
        Stream<String> s2 = names.stream().filter(s-> s.startsWith("张"));
        Set<String> zhangSet= s2.collect(Collectors.toSet());
        System.out.println(zhangSet);

        Stream<String> s3 = names.stream().filter(s-> s.startsWith("张"));
        //String[] arrs=s3.toArray(s->new String[s]);
        //String[] arrs=s3.toArray(String[]::new);
        Object[] arrs= s3.toArray();
        System.out.println("Arrays数组内容："+ Arrays.toString(arrs));

    }
}

